/**
 * 
 */
package tcss543.cpap;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Set;

import tcss543.cpap.ashish.UniformCrossoverGABasedSolver;
import tcss543.cpap.common.Utilities;
import tcss543.cpap.data.DataGenerator;
import tcss543.cpap.data.DataSetSkewType;
import tcss543.cpap.data.PaperSetSize;

/**
 * @author ashish
 * 
 */
public class Main {
	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		runRequiredTests();
	}

	/**
	 * First unscientific simple test to check data generation, and calculate
	 * cost.
	 */
	static void runRequiredTests() {
		final int runs = 4;

		for (PaperSetSize ds : PaperSetSize.values()) {
			//for (DataSetSkewType skew : DataSetSkewType.values()) {
				long totalTime = 0;
				double totalQuality =0;
				DataSetSkewType skew = DataSetSkewType.RANDOM;
				System.out
						.println("*******************************************");
				System.out.println("Generating data set of size " + ds.name()
						+ " with skew " + skew.name() + ".");

				for (int run = 1; run <= runs; run++) {
					System.out.println("\tRun# = " + run);
					DataGenerator dg = new DataGenerator(ds, skew);
					System.out.println("\tData generated...");
					// System.out.println(dg.toString());
					UniformCrossoverGABasedSolver gaS = new UniformCrossoverGABasedSolver(
							dg.getPapers(), dg.getReviewers());

					long start = System.currentTimeMillis();
					Map<Short, Set<Short>> solution = gaS.solve().getSolution(
							dg.getPapers(), dg.getReviewers());
					long end = System.currentTimeMillis();

					// Uncomment if you want to see solution
					/*
					 * for (short r : solution.keySet()) {
					 * System.out.print("Reviewer " + r + " = "); for (short p :
					 * solution.get(r)) { System.out.print(p + ","); }
					 * System.out.println(); }
					 */
					BigDecimal qual = Utilities.calculateQuality(solution, dg
							.getPapers(), dg.getReviewers(), false);
					System.out.println("\tQuality of solutin = "
							+ qual);
					System.out.println("\tTime takein in milliseconds = "
							+ (end - start));
					totalTime += (end -start);
					totalQuality += qual.doubleValue();
				}

				System.out.println("Average solution quality = " + totalQuality/runs);
				System.out.println("Average time = " + totalTime/runs);
				System.out
						.println("*******************************************");

			//}
		}
	}

}
